package com.example.yiwei.crm.json;

import android.util.Log;

import com.example.yiwei.crm.entity.ApointmentEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DHN on 2017/5/3.
 */

public class ApointmentJson {
    public static List<ApointmentEntity> getApointment(String result) {
        List<ApointmentEntity> apointmentEntityList;
        try {
            JSONObject JSON = new JSONObject(result);
            Log.d("ccccc",result);
            apointmentEntityList = new ArrayList<>();
            if (JSON.getJSONArray("list")!=null){
                JSONArray array = JSON.getJSONArray("list");
                for (int i = 0; i < array.length(); i++) {
                    ApointmentEntity apointmentEntity = new ApointmentEntity();
                    JSONObject object = array.getJSONObject(i);
                    //预约ID
                    if (object.has("KYA01")) {
                        apointmentEntity.setAppoint_id(object.getInt("KYA01"));
                    }
                    if (object.has("KAA03")){
                        apointmentEntity.setCustomer_age(object.getInt("KAA03"));
                    }
                    //单据状态
                    if (object.has("KYA77")){
                        apointmentEntity.setDj_state(object.getInt("KYA77"));
                    }
                    //预约时间
                    if (object.has("KYA02L")) {
                        apointmentEntity.setAppoint_date(object.getString("KYA02L"));
                    }
                    //预约医院
                    if (object.has("UAA03")) {
                        apointmentEntity.setAppoint_hospital(object.getString("UAA03"));
                    }
                    //预约客户
                    if (object.has("KAA02")) {
                        apointmentEntity.setCustomer_name(object.getString("KAA02"));
                    }
                    //预约客户id
                    if (object.has("KAA01")) {
                        apointmentEntity.setCustomer_id(object.getInt("KAA01"));
                    }
                    //预约科室
                    if (object.has("ADD03")) {
                        apointmentEntity.setAppint_department(object.getString("ADD03"));
                    }
                    //预约医生
                    if (object.has("ADE03")) {
                        apointmentEntity.setAppoint_doctor(object.getString("ADE03"));
                    }
                    //预约病种分类ID
                    if (object.has("AKB01")) {
                        apointmentEntity.setDisease_category_id(object.getInt("AKB01"));
                    }
                    if (object.has("AKB03")) {
                        apointmentEntity.setDisease_category(object.getString("AKB03"));
                    }
                    //预约病种
                    if (object.has("AKM03")) {
                        apointmentEntity.setDisease(object.getString("AKM03"));
                    }
                    if (object.has("AKM01")) {
                        apointmentEntity.setDisease_id(object.getInt("AKM01"));
                    }
//                    预约备注
                    if (object.has("KYA03")) {
                        apointmentEntity.setAppoint_additional(object.getString("KYA03"));
                    }
                    if (object.has("AKC03")) {
                        apointmentEntity.setClue_channel_classification(object.getString("AKC03"));
                    }
                    if (object.has("AKC01")) {
                        apointmentEntity.setClue_channel_classification_id(object.getInt("AKC01"));
                    }
                    if (object.has("AKD03")) {
                        apointmentEntity.setClue_channel_source(object.getString("AKD03"));
                    }
                    if (object.has("KAA04")){
                        apointmentEntity.setCustomer_gender(object.getInt("KAA04"));
                    }
                    if (object.has("AKD01")) {
                        apointmentEntity.setClue_channel_source_id(object.getInt("AKD01"));
                    }
                    if (object.has("KYA09L")) {
                        apointmentEntity.setTriage_date(object.getString("KYA09L"));
                    }
                    //未到原因
                    if (object.has("KYA14")) {
                        apointmentEntity.setNo_reason(object.getInt("KYA14"));
                    }
                    //省
                    if (object.has("KAA30")){
                        apointmentEntity.setPname(object.getString("KAA30"));
                    }
                    if (object.has("KLA06")){
                        apointmentEntity.setContact_phone_number(object.getString("KLA06"));
                    }
                    if (object.has("KAA31")){
                        apointmentEntity.setCname(object.getString("KAA31"));
                    }
                    if (object.has("KAA32")){
                        apointmentEntity.setAname(object.getString("KAA32"));
                    }
                    if (object.has("KYA13")) {
                        apointmentEntity.setAppointment_state(object.getInt("KYA13"));
                    }
                    if (object.has("KMA09L")){
                        apointmentEntity.setMyd(object.getString("KMA09L"));
                    }
                    if (object.has("KYA82")) {
                        apointmentEntity.setIs_add(object.getInt("KYA82"));
                    }
                    //创建时间
                    if (object.has("CTS01L")) {
                        apointmentEntity.setCreate_time(object.getString("CTS01L"));
                    }
                    //创建人
                    if (object.has("CID03")) {
                        apointmentEntity.setCurrent_create_name(object.getString("CID03"));
                    }
                    //接待人
                    if (object.has("KYA78")) {
                        apointmentEntity.setJd_id(object.getInt("KYA78"));
                    }
                    //接待人
                    if (object.has("KYA79")) {
                        apointmentEntity.setJd_name(object.getString("KYA79"));
                    }
                    //预约人
                    if (object.has("KYA19")) {
                        apointmentEntity.setYy_id(object.getInt("KYA19"));
                    }
                    //预约人
                    if (object.has("KYA20")) {
                        apointmentEntity.setYy_name(object.getString("KYA20"));
                    }
                    //预约号
                    if (object.has("KYA11")) {
                        apointmentEntity.setAppointment_number(object.getString("KYA11"));
                    }
                    if (object.has("UAA02")){
                        apointmentEntity.setTriage_hospital_code(object.getString("UAA02"));
                    }

                    apointmentEntityList.add(apointmentEntity);
                }
                return apointmentEntityList;
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
